package com.fenghongzhang.day005test2.model;

import android.util.Log;

import com.fenghongzhang.day005test2.common.RetrofitUtil;
import com.fenghongzhang.day005test2.common.UserApi;
import com.fenghongzhang.day005test2.contract.UserContract;
import com.fenghongzhang.day005test2.entity.User;
import com.fenghongzhang.mvp_lib.model.BaseModel;

import java.util.concurrent.TimeUnit;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

public class UserModel extends BaseModel implements UserContract.IUserModel {

    private static final String TAG = "UserModel";
    @Override
    public void register(String name,String pwd,Observer<User> observer) {
        //操作数据的地方
//        Retrofit retrofit = new Retrofit.Builder()
////                .client(new OkHttpClient.Builder().connectTimeout(10, TimeUnit.SECONDS).addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY)).build())
////                .addConverterFactory(GsonConverterFactory.create())
////                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
////                .baseUrl("http://49.233.0.68:8080/")
////                .build();

        Retrofit retrofit = RetrofitUtil.getRetrofitUtil().getRetrofit();

        UserApi userApi = retrofit.create(UserApi.class);
        userApi.register(name,pwd)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);

    }

    //3 model
    @Override
    public void destroy() {
        super.destroy();
        Log.i(TAG, "destroy: ");
    }
}
